package com.douma._2022;

import java.util.*;

/**
 * 抖码算法，让算法学习变的简单有趣
 *
 * @作者 : 老汤
 */
public class 统计射击比赛成绩 {

    private static class Player {
        int id;
        // 当前选手第一高的分
        int firstScore;
        // 当前选手第二高的分
        int secondScore;
        // 当前选手第三高的分
        int thirdScore;

        Player(int id) {
            this.id = id;
            this.firstScore = -1;
            this.secondScore = -1;
            this.thirdScore = -1;
        }

        public void addScore(int score) {
            // 统计当前选手的前 3 高的分
            if (score >= firstScore) {
                thirdScore = secondScore;
                secondScore = firstScore;
                firstScore = score;
            } else if (score >= secondScore) {
                thirdScore = secondScore;
                secondScore = score;
            } else if (score > thirdScore) {
                thirdScore = score;
            }
        }

        public boolean isValid() {
            // 如果没一个选手没有第 3 高的分，说明没有参加 3 次射击，所以成绩无效
            return this.thirdScore != -1;
        }

        public int getTotalScores() {
            if (isValid()) {
                return this.firstScore + this.secondScore + this.thirdScore;
            }
            // 如果成绩无效，则返回 -1
            return -1;
        }
    }

    public static void main(String[] args) {
        // 初始化 100 个选手，之所以是 100 ，因为题目规定了选手ID 的范围为（0<=ID<=99）
        Player[] players = new Player[100];
        for (int i = 0; i < 100; i++) {
            players[i] = new Player(i);
        }

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();

        String[] ids =  sc.nextLine().split(",");
        String[] scores = sc.nextLine().split(",");

        // 分别统计每个选手的射击分数
        for (int i = 0; i < n; i++) {
            int id = Integer.valueOf(ids[i]);
            int score = Integer.valueOf(scores[i]);
            players[id].addScore(score);
        }

        // 对选手排序
        Arrays.sort(players, new Comparator<Player>() {
            @Override
            public int compare(Player p1, Player p2) {
                int p1Score = p1.getTotalScores();
                int p2Score = p2.getTotalScores();
                if (p1Score != p2Score) {
                    // 按照分数降序排列
                    return p2Score - p1Score;
                } else {
                    // 如果分数相同，则按照 id 降序排列
                    return p2.id - p1.id;
                }
            }
        });

        // 打印出有成绩的选手的序号，且按照分数降序排列
        StringBuilder res = new StringBuilder();
        for (Player p : players) {
            if (p.isValid()) {
                res.append(String.format("%d,", p.id));
            }
        }
        // 去掉最后一个逗号
        System.out.println(res.toString().substring(0, res.length() - 1));

        sc.close();
    }
}
